package com.jiyun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jiyun.mapper.DriverPerformanceMapper;
import com.jiyun.service.IDriverPerformanceService;
import com.jiyun.statistical.pojo.DriverPerformance;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-02-12
 */
@Service
public class DriverPerformanceServiceImpl extends ServiceImpl<DriverPerformanceMapper, DriverPerformance> implements IDriverPerformanceService {

    @Override
    public PageInfo<DriverPerformance> findPerformanceAll(DriverPerformance driverPerformance, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);

        // 构建查询条件
        LambdaQueryWrapper<DriverPerformance> wrapper = Wrappers.lambdaQuery(DriverPerformance.class);

        // 添加时间范围查询条件
        if (!StringUtils.isEmpty(driverPerformance.getPerformanceTimeStart()) &&
                !StringUtils.isEmpty(driverPerformance.getPerformanceTimeEnd())) {
            wrapper.ge(DriverPerformance::getPerformanceTime, driverPerformance.getPerformanceTimeStart())
                    .le(DriverPerformance::getPerformanceTime, driverPerformance.getPerformanceTimeEnd());
        }

        List<DriverPerformance> performanceList = baseMapper.selectList(wrapper);
        // 构建分页对象
        PageInfo<DriverPerformance> performancePage = new PageInfo<>(performanceList);

        // 封装分页结果
        return performancePage;
    }
}
